package edu.ynmd.parm2.action;


import edu.ynmd.parm2.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class PublicAction {
    @RequestMapping("getServerString")
    @ResponseBody
    public String returnAnString(){
        return "服务器端返回的字符串";
    }

//http://localhost:81/getParmValue?sid=abc123
@GetMapping("getParmValue")
@ResponseBody
public String getParmValue(@RequestParam String sid){
        return sid;
}

//http://localhost:81/getPathValue/def456
@GetMapping("getPathValue/{sid}")
    @ResponseBody
    public String getPathValue(@PathVariable(name = "sid")String sid){
    return sid;
}

//
// {
 //       "id":"id001",
 //           "stunum":"stu001",
 //           "name":"测试姓名"
 //   }



@PostMapping("receiveAnObject")
    @ResponseBody
    public Student receiveAnObject(@RequestBody Student student){
        return student;
}


@GetMapping("returnList")
    @ResponseBody
    public List<Student>returnList(){
        //泛型
        List<Student> sl=new ArrayList<>();  //容器类的实例化
    for(int i=0;i<10;i++){
        Student s=new Student();
        s.setId("id"+i);
        s.setStunum("stunum"+i);
        s.setName("name"+i);
        sl.add(s);//放入容器的对象中
    }
    return sl;
}


@PostMapping("receiveAnListParm")
    @ResponseBody
    public List<Student>receiveAnListParm(@RequestBody List<Student>sl){
        return sl;
}
}
